package com.leyou.item.web;

import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 根据父id查询分类
     * @param pid
     * @return
     */
    @RequestMapping("/category/of/parent")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByParentId(
            @RequestParam(value = "pid",defaultValue = "0") Long pid
    ){
        return ResponseEntity.ok(this.categoryService.queryCategoryListByParentId(pid));
    }


    /**
     * 根据分类集合 ids (cid1,cid2,cid3)获取分类集合
     * @param ids   id的集合
     * @return      分类信息的集合
     */
    @RequestMapping("/category/list")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByIds(
            @RequestParam("ids") List<Long> ids
    ){
        return ResponseEntity.ok(this.categoryService.queryCategoryListByIds(ids));
    }


}
